<template>
  <div style="height:100%;width:100%;position:relative;">
      <div class="pagetop">
          <div style="width: 100%;">
              <table border="0" style="width:100%;font-size:12px;white-space: nowrap;max-width: 990px;">
                  <!-- 1. -->
                  <tr>
                      <td align="right">报告单元</td>
                      <td>
                          <rm-ddl-rptunit prgno="LIS343" defaultflag="1" @change="rptunitChange" v-model="rptunitid" width="250px"></rm-ddl-rptunit>
                      </td>
                      <td align="right">急诊标志</td>
                      <td>
                          <el-select v-model="emerflag" placeholder="请选择" clearable style="width:140px">
                              <el-option key="all" label="全部" value="all"></el-option>
                              <el-option key="0" label="常规" value="0"></el-option>
                              <el-option key="1" label="加急" value="1"></el-option>
                          </el-select>
                      </td>
                      <td align="right">申请科室</td>
                      <td>
                          <rm-ddl-common v-model="req_deptno" datatype="dept" dataname="科室" clearable width="160px" @change="reqdeptChange"></rm-ddl-common>
                      </td>
                      <td align="right">报告单元多选</td>
                      <td colspan="4">
                          <rm-ddl-rptunit ref="rptunitTwo" prgno="LIS343" :multiple_choice="true" v-model="rptunitidlist" clearable width="160px" @change="rptunitsChange"></rm-ddl-rptunit>
                      </td>
                  </tr>
                  <!-- 2. -->
                  <tr>
                      <td align="right">报告日期</td>
                      <td>
                          <el-date-picker v-model="sample_startdt" type="date" :clearable="false" placeholder="开始日期" :picker-options="samplePickerOptions" value-format="yyyy-MM-dd" style="width:116px">
                          </el-date-picker> 至
                          <el-date-picker v-model="sample_enddt" type="date" :clearable="false" placeholder="结束日期" :picker-options="samplePickerOptions" value-format="yyyy-MM-dd" style="width:116px">
                          </el-date-picker>
                      </td>
                      <td align="right">标本类型</td>
                      <td>
                          <rm-ddl-common ref="ddlspecimen" datatype="specimen" dataname="标本类型" v-model="specimen_code" clearable width="140px" @change="specimenChange"></rm-ddl-common>
                      </td>
                      <td align="right">病人来源</td>
                      <td>
                          <el-select v-model="pat_typecode" placeholder="请选择" clearable style="width:160px">
                              <el-option v-for="(item,index) in pat_typecodeList" :key="index" :value="item.codeno" :label="item.codena"></el-option>
                          </el-select>
                      </td>
                      <td align="right">病人病区</td>
                      <td>
                          <rm-ddl-common :appendtobody="true" datatype="ward" dataname="病区" v-model="req_wardno" clearable width="160px" @change="reqwardChange"></rm-ddl-common>
                      </td>
                  </tr>
                  <!-- 3. -->
                  <tr>
                      <td align="right">标本编号</td>
                      <td>
                          <el-input size="small" style="width:250px;" v-model="sampleno" placeholder="1,2,5-8等格式"></el-input>
                      </td>
                      <td align="right" colspan="4" style="border: solid 1px #cccccc;text-align: center;">
                          <el-radio v-model="reportState" label="1">所有项目</el-radio>
                          <el-radio v-model="reportState" label="2">未审核的报告项目</el-radio>
                          <el-radio v-model="reportState" label="3">未出结果的报告项目</el-radio>
                      </td>
                      <td align="left" colspan="2">
                          <!-- <el-checkbox v-model="barcodeState" @change="checkBarcode">显示无条码标本</el-checkbox> -->
                          <el-checkbox v-model="filterState" @change="checkFilterState">仅显示过滤后的项目</el-checkbox>
                          <span style="margin: 0 5px 0 15px;">标签打印份数</span>
                          <el-input size="small" style="width:30px;" v-model="printNum"></el-input>
                      </td>
                  </tr>

              </table>
              <div class="operation-list">
                  <el-button icon="el-icon-search" type="primary" @click="queryData" v-has="'PINQUERY'">查询</el-button>
                  <el-button @click="sortData" class="el-icon-sort">排序</el-button>
                  <el-button @click="clearAllData" class="el-icon-refresh-left">清除</el-button>
                  <el-button @click="btnRePrint(1)" class="el-icon-printer">打印清单</el-button>
                  <el-button v-if="rptStyleSettingState" @click="rptStyleSetting" class="el-icon-printer">打印样式设计</el-button>
                  <el-button @click="exportData" class="el-icon-upload2">导出</el-button>
                  <el-button @click="setExportColumn">导出列设置</el-button>
                  <el-button @click="btnRePrint(2)" class="el-icon-printer">打印条码</el-button>
              </div>
          </div>
      </div>
      <div class="pagecenter">
          <div class="middle-center">
              <vxe-table ref="xTable1" :data.sync="sampleData" :loading="sampleLoading" border height="auto" size="mini" stripe 
                  highlight-current-row highlight-hover-column show-header-overflow resizable show-overflow header-align="center" 
                  :optimization="{animat: false}" @current-change="currentChangeEvent" :sort-config="{trigger: 'cell'}">
                  <vxe-table-column type="index" title="序号" width="40" align="center" sortable></vxe-table-column>
                  <vxe-table-column field="emer_flag" title="加急" width="50" align="center" sortable>
                      <template v-slot="{ row, rowIndex, columnIndex }">
                          <div :key="row.reportid+rowIndex+columnIndex" v-if="row.emer_flag == '0'">
                              <el-checkbox disabled></el-checkbox>
                          </div>
                          <div :key="row.reportid+rowIndex+columnIndex" v-else>
                              <el-checkbox checked disabled></el-checkbox>
                          </div>
                      </template>
                  </vxe-table-column>
                  <vxe-table-column field="rptunitname" title="报告单元" width="150" sortable></vxe-table-column>
                  <vxe-table-column field="sampledate" title="标本日期" :formatter="['toDateString', 'yyyy-MM-dd']" width="80" align="center" sortable></vxe-table-column>
                  <vxe-table-column field="sampleno" title="标本编号" width="80" align="center" sortable sort-width="20"></vxe-table-column>
                  <vxe-table-column field="pat_name" title="病人姓名" width="80" align="center" sortable></vxe-table-column>
                  <vxe-table-column field="cp_itemnames" title="检验项目" width="250" sortable></vxe-table-column>
                  <!-- <vxe-table-column v-if="cp_itemState" field="cp_itemnames_mx" title="检验项目(明细)" width="250" sortable show-overflow></vxe-table-column> -->
                  <vxe-table-column field="test_info" title="上机信息" width="100" sortable></vxe-table-column>
                  <vxe-table-column field="report_comm" title="备注" width="120px" sortable></vxe-table-column>
                  <vxe-table-column field="pat_no" title="病人号" width="100" sortable></vxe-table-column>
                  <vxe-table-column field="pat_cardno" title="病人卡号" width="100" align="center" sortable></vxe-table-column>
                  <vxe-table-column field="pat_sex" title="性别" width="50" :formatter="sexFormat" align="center" sortable></vxe-table-column>
                  <vxe-table-column field="pat_agestr" title="年龄" width="50" align="center" sortable></vxe-table-column>
                  <vxe-table-column field="specimen_name" title="标本类型" width="100" sortable></vxe-table-column>
                  <vxe-table-column field="req_bedno" title="床号" width="50" align="center" sortable></vxe-table-column>
                  <vxe-table-column field="pat_typecodename" title="病人类别" width="100" sortable></vxe-table-column>
                  <vxe-table-column field="barcode" title="条码号" width="100" sortable></vxe-table-column>
                  <vxe-table-column field="pat_idcardno" title="身份证/护照号" width="180" sortable></vxe-table-column>
                  <vxe-table-column field="deptname" title="申请科室" width="100" sortable></vxe-table-column>
                  <vxe-table-column field="req_wardno_name" title="病人病区" width="100" sortable></vxe-table-column>
                  <vxe-table-column field="chargetypename" title="收费类别" width="100" sortable></vxe-table-column>
                  <vxe-table-column field="pat_diag" title="临床诊断" width="100" sortable></vxe-table-column>
                  <vxe-table-column field="req_dt" title="申请时间" width="120" sortable></vxe-table-column>
                  <vxe-table-column field="req_docno_name" title="申请医生" align="center" width="80" sortable></vxe-table-column>
                  <vxe-table-column field="sampled_dt" title="采样时间" width="120" sortable></vxe-table-column>
                  <vxe-table-column field="sampled_user_name" title="采样人" align="center" width="80" sortable></vxe-table-column>
                  <vxe-table-column field="recieve_dt" title="接收时间" width="120" sortable></vxe-table-column>
                  <vxe-table-column field="input_dt" title="录入时间" width="120" sortable></vxe-table-column>
                  <vxe-table-column field="input_user_name" title="录入人" align="center" width="80" sortable></vxe-table-column>
                  <vxe-table-column field="specimen_comm" title="标本状态备注" width="100" sortable></vxe-table-column>
                  <vxe-table-column field="reportid" title="报告ID" width="150" sortable></vxe-table-column>
                  <vxe-table-column field="hospitalname" title="医院" width="150" sortable></vxe-table-column>
                  <vxe-table-column field="report_user_name" title="检验医生" align="center" width="80" sortable></vxe-table-column>
                  <vxe-table-column field="rechk_dt" title="审核时间" width="120" sortable></vxe-table-column>
                  <vxe-table-column field="rechk_user_name" title="审核人" align="center" width="80" sortable></vxe-table-column>
              </vxe-table>
          </div>
          <div class="middle-right">
              <div class="right-inser">
                  <div>
                      <el-input ref="barcode" class="top-search" v-model="reqitem" @keyup.enter.native="acceptReqitem" size="small" clearable placeholder="检验项目过滤"></el-input>
                  </div>
                  <div class="middle-tab-top">
                      <vxe-table ref="ymresulttable" :data.sync="itemList" :loading="itemLoading" :select-config="{reserve: true}" :sort-config="{trigger: 'cell'}" border height="auto" how-header-overflow header-align="center" resizable show-overflow size="mini" stripe show-header-overflow :optimization="{animat: false}" max-height="calc(100% - 50px)" @cell-click="cellClickEvent" :row-class-name="getRowClassName">
                          <div class="table-content">
                              <vxe-table-column field="rpt_itemname" title="检验项目" width="166" sortable></vxe-table-column>
                              <vxe-table-column key="cp_samplecnt" field="count_num" align="center" title="标本数" width="50" sortable></vxe-table-column>
                          </div>
                      </vxe-table>
                      <div class="middle-tab-note">
                          <el-button @click.native="filterReport">过滤</el-button>
                          <div>
                              <span>标本合计：{{sampleNum}}</span>
                              <span>过滤合计：{{filterNum}}</span>
                          </div>
                      </div>
                  </div>
              </div>
          </div>
      </div>
      <el-dialog title="导出列选择" :visible.sync="chooseColumndialogVisible" width="380px" v-el-drag-dialog :close-on-click-modal="false">
          <rm-excolsetting :excolPro="excolPro" :allTableCol="allTableCol" @change="saveExportColumn"></rm-excolsetting>
      </el-dialog>
      <rm-excolsetting :excolPro="excolPro" :allTableCol="allTableCol" @change="saveExportColumn" ref="excolset" v-show="false"></rm-excolsetting>
  </div>
</template>

<script>
import XEUtils from "xe-utils";
import excelExport from "@/components/common/excelexport"; 
import RmExcolsetting from "@/components/rmcompents/rm_excolsetting.vue";
export default {
  name: "LIS343",
  components: { RmExcolsetting },
  data() {
      var self = this;
      return {
          rptStyleSettingState: false,
          rptunitid: "", // 报告单元
          emerflag: "", // 急诊标志
          req_deptno: "", // 申请科室
          rptunitidlist: "", // 报告单元多选
          sample_startdt: XEUtils.toDateString(new Date(), "yyyy-MM-dd"),
          sample_enddt: XEUtils.toDateString(new Date(), "yyyy-MM-dd"),
          specimen_code: "", // 标本类型
          pat_typecode: "", // 病人来源
          req_wardno: "", // 病区
          sampleno: "", // 标本号
          reportState: "1",
          printNum: 1, // 打印份数，与查询无关
          filterState: false,
          samplePickerOptions: {
              // disabledDate(time) {
              //     return time.getTime() > Date.now();
              // },
              shortcuts: [{
                  text: '今天',
                  onClick(picker) {
                      picker.$emit('pick', new Date());
                      self.sample_startdt = new Date();
                      self.sample_enddt = new Date();
                  }
              }]
          },
          pat_typecodeList: [], // 病人来源列表
          no_fliter_sampleData: [], // 过滤后包含所有检验项目的数据
          new_sampleData: [], // 过滤后仅包含过滤检验项目的数据
          sampleData: [],
          sampleLoading: false,
          selectRow: {}, // 当前选中行
          rpt_itemcodeList: [], // 需要过滤的检验项目数组
          rpt_itemnameList: [],
          reqitem: "",
          fitemList: [],
          itemList: [],
          itemLoading: false,
          sampleNum: 0, // 标本合计
          filterNum: 0, // 过滤合计
          excolPro: "lis343",
          chooseColumndialogVisible: false,
          allTableCol: [],
          rptItemstyle: "",
          reqdeptname: "",
          rptunitsname: "",
          specimenname: "",
          reqwardname: "",
      }
  },
  created() {
      this.getLoginutype();
  },
  mounted() {
      this.getpatTypeList();
      this.getPrintId();
      this.initRptunit();
  this.$refs.excolset.colSettingToDB();
  },
  watch: {
      rptunitidlist(val, newval) {
          this.rptunitid = "";
      }
  },
  methods: {
      initRptunit() {
          let rptunit = localStorage.getItem("lis343rptunit");
          if (rptunit)  {
              let rptunitList = [];
              rptunitList = rptunit.split(",");
              setTimeout(() => {
                  if (rptunitList.length > 1) {
                      this.rptunitidlist = rptunit;
                      this.rptunitid = 0;
                  } else {
                      this.rptunitid = rptunit;
                      this.rptunitidlist = "";
                  }
              }, 1000);
          }
      },
      getLoginutype() {
          let loginutype = this.$tool.getSession(this.$tool.loginutype);
          if (loginutype == "G") {
              this.rptStyleSettingState = true;
          }
      },
      getpatTypeList() {
          this.$tool
              .request({
                  url: "LIS/LIS3/LIS343",
                  method: "post",
                  data: {
                      action: "pat_type_query"
                  }
              })
              .then(res => {
                  if (res.errcode == 1) {
                      this.pat_typecodeList = res.Data;
                  } else {
                      this.$message.error(res.Data);
                  }
              })
              .catch(e => {
                  this.$message.error(e);
              });
      },
      getPrintId() {
          this.$tool
              .request({
                  url: "LIS/LIS3/LIS343",
                  method: "post",
                  data: {
                      action: "InitOptions"
                  }
              })
              .then(res => {
                  this.barcodestyle = res.barcodestyle;
                  this.cxbarcodeprinter = res.cxbarcodeprinter;
                  this.rptItemstyle = res.rptItemstyle;
              });
      },
      queryData() {
          this.selectRow = {};
          this.queryLabReport();
          this.getItemList();
      },
      queryLabReport() {
          let rptunit = this.rptunitid ? this.rptunitid : this.rptunitidlist;
          localStorage.setItem("lis343rptunit", rptunit); // 记录当前报告单元选项值 本地
          this.report_Loading = true;
          this.$tool
              .request({
                  url: "LIS/LIS3/LIS343",
                  method: "post",
                  data: {
                      action: "lab_report_query",
                      rptunitid: Number(this.rptunitid),
                      emerflag: this.emerflag,
                      pat_typecode: this.pat_typecode,
                      rptunitlist: this.rptunitid ? "" : this.rptunitidlist,
                      sample_startdt: this.sample_startdt,
                      sample_enddt: this.sample_enddt,
                      specimen_code: this.specimen_code, // 标本类型
                      req_deptno: this.req_deptno, // 申请科室
                      barcode: this.barcodeState ? "" : "false", // 默认不选中，查询有条码标本；选中，有无条码都显示
                      sampleno: this.sampleno, // 标本号
                      req_wardno: this.req_wardno, // 病区
                      reportState: this.reportState,
                      // rpt_itemcode: type == 1 ? itemStr : '',
                  }
              })
              .then(res => {
                  this.report_Loading = false;
                  if (res.errcode == 1) {
                      if (res.Data) {
                          this.sampleDataCopy = XEUtils.clone(res.Data, true);
                          this.sampleData = res.Data;
                          this.new_sampleData = res.Data;
                          this.no_fliter_sampleData = res.Data;
                          this.sampleNum = res.Data.length;
                      }
                  } else {
                      this.sampleData = [];
                      this.sampleDataCopy = [];
                      this.sampleNum = 0;
                      this.new_sampleData = [];
                      this.no_fliter_sampleData = [];
                  }
              })
              .catch(e => {
                  this.$message.error(e);
              });
      },
      getItemList() {
          this.itemLoading = true;
          this.rpt_itemcodeList = [];
          this.rpt_itemnameList = [];
          this.filterNum = 0;
          this.$tool
              .request({
                  url: "LIS/LIS3/LIS343",
                  method: "post",
                  data: {
                      action: "req_item_query",
                      rptunitid: Number(this.rptunitid),
                      emerflag: this.emerflag,
                      pat_typecode: this.pat_typecode,
                      rptunitlist: this.rptunitid ? "" : this.rptunitidlist,
                      sample_startdt: this.sample_startdt,
                      sample_enddt: this.sample_enddt,
                      specimen_code: this.specimen_code, // 标本类型
                      req_deptno: this.req_deptno, // 申请科室
                      barcode: this.barcodeState ? "" : "false", // 默认不选中，查询有条码标本；选中，有无条码都显示
                      sampleno: this.sampleno, // 标本号
                      req_wardno: this.req_wardno, // 病区
                      reportState: this.reportState,
                  }
              })
              .then(res => {
                  this.itemLoading = false;
                  if (res.errcode == 1) {
                      this.fitemList = XEUtils.clone(res.Data, true);
                      this.itemList = res.Data;
                  } else {
                      this.itemList = [];
                      this.fitemList = [];
                  }
              });
      },
      btnRePrint(btype) {
          // btype 打印类型 1：打印 2：打印条码
          var that = this;
          if (btype == 1) {
              that.listPrint('print');
          }
          if (btype == 2) {
              var fullData = that.$refs.xTable1.getTableData().fullData;
              if (JSON.stringify(that.selectRow) == "{}" && fullData.length == 0) return false;
              if (!that.printNum) {
                  this.$pub.message(this, "提示：请先输入标签打印份数！", "warning");
                  return false;
              }
              that.$confirm("请选择打印当前选中条码还是所有表格条码，（共" + that.printNum + "张）?", "提示", {
                  confirmButtonText: "打印当前选中条码",
                  cancelButtonText: "打印当前表格条码",
                  distinguishCancelAndClose: true,
                  closeOnClickModal: false,
                  type: "warning"
              }).then(() => {
                  if (JSON.stringify(that.selectRow) != "{}") {
                      if (that.barcodestyle != "") {
                          for (var j = 1; j <= that.printNum; j++) {
                              that.$pub.printbarcode(that, that.selectRow.barcode, "1", that.barcodestyle, that.cxbarcodeprinter, "1");
                          }
                      } else {
                          that.$alert("没有设置条码的打印样式", "错误", {
                              confirmButtonText: "确定"
                          });
                      }
                  } else {
                      that.$alert("至少选择一个要重打的条码！", "请选择", {
                          confirmButtonText: "确定"
                      });
                  }
              })
              .catch((e) => {
                  if (e == 'close') return false;
                  if (fullData.length > 0) {
                      fullData.forEach(element => {
                          that.$pub.printbarcode(that, element.barcode, "1", that.barcodestyle, that.cxbarcodeprinter, "1");
                      });
                  }
              });
          }
      },
      sortData() {
          if (this.tableColumn.length == 0) {
              let columns = this.$refs.xTable1.getColumns();
              columns.forEach(item => {
                  this.tableColumn.push({ title: item.title, field: item.property });
              });
          }
          this.$rmsort(
              { tableColumn: this.tableColumn, sortArr: this.sortArr },
              {
                  confirmButtonText: "确定",
                  cancelButtonText: "取消",
                  type: "warning"
              }
          )
              .then(res => {
                  this.sortArr = res.data;
                  this.InitPage();
              })
              .catch(() => {});
      },
      reqdeptChange(code, name) {
          this.req_deptno = code;
          this.reqdeptname = name;
      },
      rptunitsChange(code, name) {
          this.rptunitidlist = code;
          this.rptunitsname = name;
      },
      specimenChange(code, name) {
          this.specimen_code = code;
          this.specimenname = name;
      },
      reqwardChange(code, name) {
          this.req_wardno = code;
          this.reqwardname = name;
      },
      // 导出
      exportData() {
          var rightlocalStorage = JSON.parse(window.localStorage.getItem(this.excolPro + "exportCol"));
          // var rightlocalStorage = JSON.parse(window.localStorage.getItem("exportColumn"));
          var exportColumn = [];
          let column = this.$refs.xTable1.getTableColumn().tableColumn;
          if (rightlocalStorage && rightlocalStorage.length > 0) {
              let columnArr = [];
              rightlocalStorage.forEach(item => {
                  columnArr.push({
                      title: item.extitle ? item.extitle : item.title,
                      property: item.property
                  });
              });
              exportColumn = columnArr;
          } else {
              exportColumn = this.$pub.InitColumn(column);
          }
          let data = excelExport.getExportData(this, "sampleData", exportColumn);
          let filtertxt = this.getExportFilter();
          this.$pub.exportTableExcelWithData(data, exportColumn.length, "LIS343标本检验项目总汇表.xlsx", filtertxt);
      },
      // 获取当前导出文件的所有查询条件
      getExportFilter() {
          let filtertxt = "报告日期:" + XEUtils.toDateString(this.sample_startdt, "yyyy-MM-dd") + "至" + XEUtils.toDateString(this.sample_enddt, "yyyy-MM-dd") + "; ";
          if(this.rptunitid) filtertxt += "报告单元:" + this.rptunitname + "; ";
          if(this.emerflag) filtertxt += "急诊标志:" + (this.emerflag == "0" ? "常规" : this.emerflag == "1" ? "加急" : "全部") + "; ";
          
          if(this.req_deptno) filtertxt += "申请科室:" + this.reqdeptname + "; ";
          if(this.rptunitidlist) filtertxt += "报告单元多选:" + this.rptunitsname + "; ";
          if(this.specimen_code) filtertxt += "标本类型:" + this.specimenname + "; ";
          if(this.pat_typecode) filtertxt += "病人来源:" + this.getOptionName(this.pat_typecodeList.filter((item) =>  this.pat_typecode == item.codeno)) + "; ";
          if(this.req_wardno) filtertxt += "病人病区:" + this.reqwardname + "; ";
          if(this.sampleno) filtertxt += "标本编号:" + this.sampleno + "; ";
          if(this.reportState) filtertxt += "项目状态:" + (this.reportState == "2" ? "未审核的报告项目" : this.reportState == "3" ? "未出结果的报告项目" : "所有项目") + "; ";
          if(this.filterState) filtertxt += "仅显示过滤后的项目; ";
          if(this.printNum) filtertxt += "标签打印份数:" + this.printNum + "; ";
          return filtertxt;
      },
      getOptionName(option) {
          if (option && option.length > 0) {
              let optionname = "";
              option.forEach((item) => {
                  if(item.hasOwnProperty("codena")) {
                      optionname += item.codena + ",";
                  } else if(item.hasOwnProperty("display")) {
                      optionname += item.display + ",";
                  } else {
                      optionname += item.label + ",";
                  }
              });
              return optionname.substring(0, optionname.length - 1);
          } else {
              return "";
          }
      },
      getExportData(columns) {
          let datas = this.sampleData;
          let headers = [columns.map(item => item.title)];
          return headers.concat(
              datas.map(row => {
                  return columns.map(column => {
                      switch (column.property) {
                          case "emer_flag":
                              return row[column.property] == "1" ? "急" : "";
                          case "pat_sex":
                              if (!row[column.property]) {
                                  return "";
                              } else {
                                  return row[column.property] == "1" ? "男" : "女";
                              }
                          default:
                              return row[column.property];
                      }
                  });
              })
          );
      },
      setExportColumn() {
          let allColumnList = [];
          this.$refs.xTable1.getTableColumn().tableColumn.forEach(element => {
              if (element.property) {
                  allColumnList.push({
                      title: element.title,
                      property: element.property
                  });
              }
          });
          this.allTableCol = allColumnList;
          this.chooseColumndialogVisible = true;
      },
      saveExportColumn() {
          this.chooseColumndialogVisible = false;
      },
      rptunitChange(code, name) {
          this.rptunitid = code;
          this.rptunitname = name;
          this.rptunitlist = "";
          this.$refs.rptunitTwo.finallvalue = "";
      },
      checkFilterState(e) {
          this.filterState = e;
          if (e) {
              this.sampleData = this.new_sampleData;
          } else {
              this.sampleData = this.no_fliter_sampleData;
          }
      },
      clearAllData() {
          this.sampleData = [];
          this.fitemList = [];
          this.itemList = [];
          this.rptunitid = "";
          this.rptunitidlist = "";
          this.sample_startdt = XEUtils.toDateString(new Date(), "yyyy-MM-dd");
          this.sample_enddt = XEUtils.toDateString(new Date(), "yyyy-MM-dd");
          this.pat_typecode = "";
          this.emerflag = "";
          this.specimen_code = "";
          this.sampleno = "";
          this.reportState = "1";
          this.req_wardno = "";
          this.req_deptno = "";
          this.rpt_itemnameList = [];
          this.rpt_itemcodeList = [];
          this.filterNum = 0;
          this.sampleNum = 0;
      },
      cellClickEvent({ row, column }) {
          var code = row.rpt_itemcode;
          var idx = this.rpt_itemcodeList.indexOf(code);
          if (idx == -1) {
              this.rpt_itemcodeList.push(code);
              this.rpt_itemnameList.push(row.rpt_itemname);
              // this.filterAllNum +=  row.count_num;
          } else {
              this.rpt_itemcodeList.splice(idx, 1);
              this.rpt_itemnameList.splice(this.rpt_itemnameList.indexOf(row.rpt_itemname), 1);
              // this.filterAllNum -=  row.count_num;
          }
      },
      sexFormat({ cellValue }) {
          if (cellValue == "All") {
              return "所有";
          } else if (cellValue == "1") {
              return "男";
          } else if (cellValue == "2") {
                  return "女";
          } else {
              return "";
          }
      },
      getRowClassName({ row, rowIndex }) {
          if (this.rpt_itemcodeList.indexOf(row.rpt_itemcode) != -1) {
              return "rm-choose"; //选中
          }
      },
      currentChangeEvent({ row, rowIndex, column, columnIndex }, event) {
          this.selectRow = row;
      },
      acceptReqitem() {
          this.rpt_itemcodeList = [];
          this.rpt_itemnameList = [];
          var arr = this.fitemList.filter(item => item.rpt_itemname.indexOf(this.reqitem) > -1);
          this.itemList = arr;
      },
      // 打印样式设计
      rptStyleSetting() {
          this.listPrint('setting');
      },
      listPrint(oper){
          // 打印
          let column = this.$refs.xTable1.getTableColumn().tableColumn;
          let str = JSON.stringify(this.$pub.InitColumn(column,'序号,seq'));
          str += "\r";
          this.$refs.xTable1.afterFullData.forEach((e,i)=>e.seq=i+1);
          str += JSON.stringify(this.$refs.xTable1.afterFullData);
          let sql = btoa(encodeURIComponent(str));
          if (oper=="print")
          {
              jsObj.PrintCustomJsonReport(this.rptItemstyle, sql, this.userno, "检验项目总汇表清单样式", "");
          }
          else {
              jsObj.SetCustomJsonPrintConfig(this.rptItemstyle, sql, this.userno, "检验项目总汇表清单样式");
          }
      },
      filterReport() {
          var that = this;
          if (that.rpt_itemnameList.length == 0) {
              that.sampleData = XEUtils.clone(that.sampleDataCopy, true);
              that.filterNum = that.sampleData.length;
              return;
          }
          that.no_fliter_sampleData = [];
          that.new_sampleData = [];
          that.sampleDataCopy.forEach(element => {
              var cp_itemnames = element.cp_itemnames;
              that.filterJudge(cp_itemnames, element);
          });
          if (that.filterState) {
              that.sampleData = that.new_sampleData;
          } else {
              that.sampleData = that.no_fliter_sampleData;
          }
          // that.sampleData = that.no_fliter_sampleData;
          that.filterNum = that.sampleData.length;
      },
      // 过滤方法判断处理
      filterJudge(itemnames, element) {
          var that = this;
          if (itemnames) {
              // if (cp_itemnames && cp_itemnames.indexOf(",") == -1) {
                  let cp_itemnames = itemnames + ",";
                  var new_cp_itemnames = "";
                  that.rpt_itemnameList.forEach(item => {
                      let i = item + ",";
                      if (cp_itemnames.indexOf(i) != -1) {
                          new_cp_itemnames += i;
                      }
                  });
                  if (new_cp_itemnames) {
                      that.no_fliter_sampleData.push(element);
                      var new_element = XEUtils.clone(element, true);
                      new_element.cp_itemnames = new_cp_itemnames.slice(0, new_cp_itemnames.length - 1);
                      that.new_sampleData.push(new_element);
                  }
              // }
              // if (cp_itemnames.indexOf(",") != -1) {
              //     var item_list = cp_itemnames.split(",");
              //     var new_cp_itemnames = "";
              //     that.rpt_itemnameList.forEach(i => {
              //         item_list.forEach(c => {
              //             if (i.trim() == c.trim()) {
              //                 new_cp_itemnames += i + ",";
              //             }
              //         });
              //     });
              //     if (new_cp_itemnames) {
              //         that.no_fliter_sampleData.push(element);
              //         var new_element = XEUtils.clone(element, true);
              //         new_element.cp_itemnames = new_cp_itemnames.slice(0, new_cp_itemnames.length - 1);
              //         that.new_sampleData.push(new_element);
              //     }
              // }
          }
      },
  },
}
</script>

<style scoped>
.pagetop {
  left: 0;
  right: 0;
  display: -webkit-box;
  -webkit-box-pack: center;
  -webkit-box-align: center;
  border: solid 1px #ccc;
  position: absolute;
  z-index: 99;
  height: 130px;
  overflow-x: auto;
  overflow-x: overlay;
}
::-webkit-scrollbar {
  width: 0px;
  height: 5px;
  border: 4px solid white;
}
::-webkit-scrollbar-thumb {
  background-color: #c1c1c1;
}
::-webkit-scrollbar-track {
  background-color: #f1f1f1;
}
/* Buttons */
::-webkit-scrollbar-button:single-button {
  background-color: #bbbbbb;
  display: block;
  border-style: solid;
  height: 5px;
  width: 5px;
}
/* Left */
::-webkit-scrollbar-button:horizontal:decrement {
  margin-right: 2px;
  border-width: 4px 4px 4px 0;
  border-color: #f1f1f1 transparent #f1f1f1 #f1f1f1;
  background-color: #000000;
}
::-webkit-scrollbar-button:horizontal:decrement:hover {
  border-color: #d2d2d2 transparent #d2d2d2 #d2d2d2;
}
/* Right */
::-webkit-scrollbar-button:horizontal:increment {
  margin-left: 2px;
  border-width: 4px 0 4px 4px;
  border-color: #f1f1f1 #f1f1f1 #f1f1f1 transparent;
  background-color: #000000;
}
::-webkit-scrollbar-button:horizontal:increment:hover {
  border-color: #d2d2d2 #d2d2d2 #d2d2d2 transparent;
}
.pagetop .el-radio {
  color: #000000 !important;
}
/deep/ .pagetop .el-checkbox__label {
  font-size: 12px;
  color: #000000;
  padding-left: 5px !important;
}
.operation-list {
  float: right;
  margin-right: 5px;
  margin-bottom: 5px;
}
.pagecenter {
  position: absolute;
  top: 135px;
  bottom: 0px;
  overflow: auto;
  width: 100%;
  left: 0px;
}
.middle-center {
  position: absolute;
  width: 79.5%;
  height: 100%;
  right: 575px;
  left: 0px;
  overflow: auto;
}
.middle-right {
  position: absolute;
  top: 0;
  bottom: 0px;
  /* overflow: visible; */
  width: 20%;
  height: 100%;
  right: 0px;
}
.right-inser {
  position: absolute;
  top: 0;
  bottom: 0px;
  /* overflow: visible; */
  width: 100%;
  height: 100%;
  right: 0px;
}
.middle-tab-top {
  width: 100%;
  height: calc(100% - 31px);
  margin-top: 5px;
  border: 1px solid #cccccc;
}
.table-content {
  height: calc(100% - 50px);
}
.middle-tab-note {
  /* position: absolute; */
  display: flex;
  margin: 5px 10px;
}
.middle-tab-note button {
  margin-top: 5px;
  margin-right: 10px;
  height: 25px;
}
.middle-tab-note div span {
  font-size: 12px;
  display: block;
}
/deep/.middle-tab-top .vxe-table {
  height: calc(100% - 50px) !important;
}
/deep/.middle-tab-top .vxe-table--body-wrapper {
  height: calc(100% - 28px) !important;
}
table {
  font-size: 12px;
  border-collapse: separate;
  border-spacing: 5px;
}
/deep/.el-checkbox__inner::after {
  border: 2px solid #000000 !important;
  box-sizing: content-box;
  content: "";
  border-left: 0 !important;
  border-top: 0 !important;
  height: 7px;
  left: 4px;
  position: absolute;
  top: 1px;
  transform: rotate(45deg) scaleY(0);
  width: 3px;
  transition: transform 0.15s ease-in 0.05s;
  transform-origin: center;
}
/deep/.el-checkbox__input.is-disabled + span.el-checkbox__label {
  color: #000000;
  cursor: not-allowed;
}
/deep/ .el-checkbox__input.is-disabled .el-checkbox__inner,
.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner + .el-input.is-disabled .el-input__inner {
  background-color: #ffffff !important;
}
/deep/.el-input--suffix .el-input__inner {
  padding-right: 5px;
}
/deep/.el-button + .el-button {
  margin-left: 5px;
}
table tr td[data-v-cf2d51fc]:nth-child(1) {
  width: 60px !important;
}
/deep/.middle-tab-top tbody {
  padding-bottom: 100px;
}
/deep/.rm-choose {
  background-color: #b6e8ff !important;
}

</style>